<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2022-11-24
 * Time: 8:22
 */

namespace App\controller\dtk;

use App\model\TbGood;
use App\server\dtk\DtkClient;
use App\server\dtk\tb\GetTbService;
use App\server\dtk\tb\ListSuperGoods;
use support\exception\BaseException;
use support\Request;
use think\facade\Db;

class Dtk
{
    public function index(Request $request)
    {
        $keyWords=$request->get('k');
        $pageNo=$request->get('p',1);
        $l=new GetTbService($keyWords,$pageNo);
        $arr=$l->map(6);
        return json($arr);
    }

    public function saveGood(Request $request)
    {
        $data=$request->post();
        $r=[];
        foreach ($data as $item)
        {
            if(empty($item['item_id'])){
                continue;
            }
            $x=TbGood::where('item_id',$item['item_id'])->find();
            if($x){
                $r[]=$x['id'];
                continue;
            }
            $t =TbGood::create($item);
            //$id=Db::table('tb_good')->insertGetId($item);
            $r[]=(int)$t['id'];
        }
        return json($r);
    }
}